import { defineStore } from 'pinia'
import axios from 'axios'

export const apiStore = defineStore('api', {
  state: () => ({
    // data: JSON.parse(localStorage.getItem('data') || '[]'),
    data: [],
    loading: false,
    error: null
  }),
  actions: {
    async fetchData() {
      this.loading = true
      try {
        const response = await axios.get('http://localhost:3000/users')
        this.data = response.data
      } catch (error) {
        this.error = error
      } finally {
        this.loading = false
      }
    }
  }
})
